package com.example.tests;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import java.util.Random;
import org.testng.annotations.*;
import com.example.utils.SortedListOf;

public class ContactModificationTests extends TestBase {

  @Test(dataProvider = "contactsFromCsvFile")
  public void modifySomeContact(ContactData contact) throws Exception {
	SortedListOf<ContactData> oldList = (SortedListOf<ContactData>) app.getHebirnateHelper().listContacts();
    Random rnd = new Random();
    int index = rnd.nextInt(oldList.size()-1);
	app.getContactHelper().modifyContact(contact, index);
	if (wantToCheck()) {
    	if ("yes".equals(app.getProperty("check.db"))) {
    		assertThat(app.getModel().getContacts(), equalTo(app.getHebirnateHelper().listContacts()));
    	}
    	if ("yes".equals(app.getProperty("check.ui"))) {
    		assertThat(app.getModel().getContacts(), equalTo(app.getContactHelper().getUiContacts()));
    	}
    }	
  }
}
